package shuashuami.hb.com.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import shuashuami.hb.com.hbclient.R;
import shuashuami.hb.com.hdlibrary.glid.GlidUtil;
import shuashuami.hb.com.model.WodeFabu;
import shuashuami.hb.com.view.AddTaskDialog;

/**
 * Created by Administrator on 2017/6/20.
 */

public class BWodeFabuTaskAadpter extends BaseAdapter {
    private LayoutInflater inflater;
    private List<WodeFabu> list;
    private Activity con;

    private GlidUtil glidUtil;

    public BWodeFabuTaskAadpter(List<WodeFabu> list, Activity context) {
        this.con = context;
        inflater = LayoutInflater.from(context);
        this.list = list;
        glidUtil = new GlidUtil(context);
    }

    @Override
    public int getCount() {
        if (null != list) {
            return list.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CdistriutionCenterViewHoler viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapter_b_wodefabu_task_layout, null);
            viewHolder = new CdistriutionCenterViewHoler();
            viewHolder.imgP = (ImageView) convertView.findViewById(R.id.img_cuntreater_task_p_image);
            viewHolder.tvNum = (TextView) convertView.findViewById(R.id.tv_cuntreater_task_task_number);
            viewHolder.imgImage = (ImageView) convertView.findViewById(R.id.img_cuntreater_task_task_image);
            viewHolder.tvMessage = (TextView) convertView.findViewById(R.id.tv_cuntreater_task_task_message);
            viewHolder.tvMoney = (TextView) convertView.findViewById(R.id.tv_cuntreater_task_task_money);
            viewHolder.tvSize = (TextView) convertView.findViewById(R.id.tv_cuntreater_task_task_size);
            viewHolder.tvTotal = (TextView) convertView.findViewById(R.id.tv_cuntreater_task_task_total);
            viewHolder.tvEndTime = (TextView) convertView.findViewById(R.id.tv_cuntreater_task_task_end_time);
            viewHolder.btnLianxi = (Button) convertView.findViewById(R.id.btn_cuntreater_task_task_lianxi_shangjia);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (CdistriutionCenterViewHoler) convertView.getTag();
        }
        final WodeFabu content = list.get(position);
        glidUtil.uploadRound(content.getPImage(), 10, viewHolder.imgP);
        glidUtil.uploadRound(content.getGoodsImage(), 10, viewHolder.imgImage);
        viewHolder.tvNum.setText("任务编号：" + content.getTaskSn());
        viewHolder.tvMessage.setText(content.getTitle());
        viewHolder.tvMoney.setText("¥ " + content.getPrice());
        viewHolder.tvSize.setText("X " + content.getNum());
        viewHolder.tvTotal.setText("¥ " + content.getCommission());
        viewHolder.tvEndTime.setText("发布时间：" + content.getAddTime());
        viewHolder.btnLianxi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AddTaskDialog addTaskDialog = new AddTaskDialog(con, content.getId());
                addTaskDialog.show();
            }
        });
        return convertView;
    }

    class CdistriutionCenterViewHoler {
        public ImageView imgP;
        public TextView tvNum;
        public ImageView imgImage;
        public TextView tvMessage;
        public TextView tvMoney;
        public TextView tvSize;
        public TextView tvTotal;
        public TextView tvEndTime;
        public Button btnLianxi;
    }


}



